package com.cy.model;

import com.cy.BasicModel;
import com.cy.ext.plugin.tablebind.TableBind;

import java.util.Date;
import java.util.List;

@TableBind(tableName="device_tag",pkName = "id")
public class DeviceTag extends BasicModel<DeviceTag> {
    public static final DeviceTag dao = new DeviceTag();
    public static final String SELECT_ALL = "`id`,`tag_name`,`create_time`,`start_time`,`end_time`,`creator`,`address`,`remark`";
            
    public DeviceTag setId(Long id){
        return this.set("id",id);
    }

    public Long getId(){
        return this.get("id");
    }
        
    public DeviceTag setTagName(String tagName){
        return this.set("tag_name",tagName);
    }

    public String getTagName(){
        return this.getStr("tag_name");
    }
        
    public DeviceTag setCreateTime(Date createTime){
        return this.set("create_time",createTime);
    }

    public Date getCreateTime(){
        return this.get("create_time");
    }
        
    public DeviceTag setStartTime(Date startTime){
        return this.set("start_time",startTime);
    }

    public Date getStartTime(){
        return this.get("start_time");
    }
        
    public DeviceTag setEndTime(Date endTime){
        return this.set("end_time",endTime);
    }

    public Date getEndTime(){
        return this.get("end_time");
    }
        
    public DeviceTag setCreator(Long creator){
        return this.set("creator",creator);
    }

    public Long getCreator(){
        return this.get("creator");
    }

    public Account getCreater(){
        return Account.dao.findById(this.getCreator());
    }
        
    public DeviceTag setAddress(String address){
        return this.set("address",address);
    }

    public String getAddress(){
        return this.getStr("address");
    }

    public DeviceTag setRemark(String remark){
        return this.set("remark",remark);
    }

    public String getRemark(){
        return this.getStr("remark");
    }


    public List<DeviceMapTag> getDeviceMapTags(){
        return DeviceMapTag.dao.findByTag(this.getId());
    }

    public List<Device> getDevices(){
        return Device.dao.find("SELECT d.* FROM device d,device_map_tag dmt WHERE d.device_id = dmt.device_id AND dmt.tag_id = ?", getId());
    }
}
